# 适用pyinstall 打包这个文件，可以生成可运行的脚本

# !/usr/bin/env python3

from gunicorn.app.base import Application
import os


class MyApplication(Application):

    def load_config(self):
        s = self.cfg.set
        get_bind = os.getenv("CHECK_FILE_EXPORTER_BIND")
        get_accesslog = os.getenv("CHECK_FILE_EXPORTER_ACCESSLOG")
        get_errorlog = os.getenv("CHECK_FILE_EXPORTER_ERRORLOG")

        bind = get_bind if get_bind else "0.0.0.0:9123"
        accesslog = get_accesslog if get_bind else "./access.log"
        errorlog = get_errorlog if get_bind else "./error.log"

        s('bind', bind)
        s('workers', 1)
        s('timeout', 30)
        s('accesslog', accesslog)
        s('errorlog', errorlog)
        s('access_log_format', '%(t)s %(h)s "%(r)s" %(s)s %(b)s %(D)s "%(a)s"')

    def load(self):
        from main import app
        return app


if __name__ == '__main__':
    MyApplication().run()
